


import * as echarts from 'echarts'

 export default {
   methods: {
     RadarGraph_V2Init(v){
       const radarGraph = {
        indicator: [
          { name: 'Sales', max: 6500 },
          { name: 'Administration', max: 16000 },
          { name: 'Information Technology', max: 30000 },
          { name: 'Customer Support', max: 38000 },
          { name: 'Development', max: 52000 },
          { name: 'Marketing', max: 25000 },
        ],
        radarSeries: [
          {
            value: [4200, 3000, 20000, 35000, 50000, 18000],
            name: 'Allocated Budget',
          },
          {
            value: [5000, 14000, 28000, 26000, 42000, 21000],
            name: 'Actual Spending',
          },
        ],
      }

      let echartEle=  this.$refs[v];
      let myChart = echarts.init(echartEle);

      const {
        dataSourceType,options,staticData
      } = this.controlProperties[v]

      if (dataSourceType === 'static' && Object.keys(staticData).length) {
        options.radar.indicator = staticData.radar.indicator
        options.series = options.series.map((item, index) => {
          return { ...item, data: staticData.series[index].data }
        })
      } else if(dataSourceType === 'static' && !Object.keys(staticData).length){
        options.radar.indicator = radarGraph.indicator
        options.series[0].data = radarGraph.radarSeries.map((item) => item)
      }
      options && myChart.setOption(options);
     },
     RadarGraph_V2SetOption(v){
        const { options, flowResult } = this.controlProperties[v]
        let {series,radar } = options
        radar.indicator = flowResult[radar.dataSource[radar.dataSource.length - 1].dataKey]
        series = series.map((item) => {
          item.data = flowResult[item.dataSource[item.dataSource.length - 1].dataKey]
        })
        let echartEle = this.$refs[v];
        let myChart = echarts.init(echartEle);
        options && myChart.setOption(options);
     }
   }
  }
